package com.hit.comm.type;

import com.hit.comm.dto.CommonResp;
import com.hit.comm.dto.RegisterInfoReq;
import com.hit.comm.dto.ServerDataResp;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author kehanjiang
 * @date 2025/03/24
 */
public enum CommTypeEnum {

    TYPE_10000(10000, "执行端注册到服务端", RegisterInfoReq.class, CommonResp.class),
    TYPE_10001(10001, "请求服务端各类数据", null, ServerDataResp.class),
    ;

    /**
     * 编码
     */
    private Integer code;

    /**
     * 描述
     */
    private String desc;

    /**
     * 请求实体类
     */
    private Class<?> reqClazz;

    /**
     * 响应实体类
     */
    private Class<?> respClazz;

    CommTypeEnum(Integer code, String desc, Class<?> reqClazz, Class<?> respClazz) {
        this.code = code;
        this.desc = desc;
        this.reqClazz = reqClazz;
        this.respClazz = respClazz;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Class<?> getReqClazz() {
        return reqClazz;
    }

    public void setReqClazz(Class<?> reqClazz) {
        this.reqClazz = reqClazz;
    }

    public Class<?> getRespClazz() {
        return respClazz;
    }

    public void setRespClazz(Class<?> respClazz) {
        this.respClazz = respClazz;
    }

    private static final Map<Integer, CommTypeEnum> MAP = Stream.of(CommTypeEnum.values())
            .collect(Collectors.toMap(CommTypeEnum::getCode, v -> v));

    public static CommTypeEnum getByType(Integer type) {
        return MAP.get(type);
    }

}